

<?php
session_start();
include DOCMENT_ROOT.'/framwork/controller.class.php';
class adminController extends controller{
    public function __construct() {
        parent::header();
        parent::smartyAction("admin");
    }
    public function register(){
        $this->smarty->display("register.html");
    }
    public function checkName(){
        $name=$_GET["name"];
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $adminModel=new adminModel();
        $result=$adminModel->checkField("name='$name'");
        if($result){
            echo"管理员可用";
        }else{
            echo"管理员已存在";
        }
    }
    public function checkTel(){
        $tel=$_GET["tel"];
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $adminModel=new adminModel();
        $result=$adminModel->checkField("tel='$tel'");
        if($result){
            echo"手机号名可用";
        }else{
            echo"手机号已存在";
        }
    }
    public function addAdmin(){
       $name=$_GET["name"];
       $pwd=$_GET["pwd"]; 
       $tel=$_GET["tel"]; 
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $adminModel=new adminModel();
       $result=$adminModel->addAdmin($name,$pwd,$tel);
       echo $result;
    }
     public function login(){
        $this->smarty->display("userdl.html");
     }
      public function checkLogin(){
        $name=$_GET["name"];
        $pwd=$_GET["pwd"]; 
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $adminModel=new adminModel();
        $arr=$adminModel->checkLogin($name,$pwd);
        $_SESSION["id"]=$arr["id"];
        if(empty($arr)){
            echo false;
        }else{
            echo true;
        }
      }
    public function adminlist(){
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $adminModel=new adminModel();
        $result=$adminModel->adminList();
        $this->smarty->assign("arr",$result);
        $this->smarty->display("adminList.html");
    }
     public function updateAdmin(){
        $id=$_GET["id"];
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $adminModel=new adminModel();
        $arr=$adminModel->selectAdmin($id);
        $this->smarty->assign("arr",$arr);
        $this->smarty->display("update.html");
    }
    public function update(){
        $id=$_GET["id"];
        $name=$_GET["name"];
        $pwd=$_GET["pwd"]; 
        $tel=$_GET["tel"]; 
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $adminModel=new adminModel();
        if(isset($_POST["pwd"]) && $_POST["pwd"] == 0){
            $arr=$adminModel->update1Admin($name,$pwd,$tel,$id);
        }else{
            $arr=$adminModel->updateAdmin($name,$tel,$id);
        }
        echo $arr;
    }
    public function delete(){
        $id=$_GET['delete1'];
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $adminModel=new adminModel();
        $result=$adminModel->deleteAdmin($id);
        echo $result;
    }


//.............................

        public function deleteArticle(){
        $id=$_GET['delete1'];
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $articleModel=new articleModel();
        $result=$articleModel->deleteArticle($id);
        echo $result;
    }
//....................
    public function index(){
        $this->smarty->display("login.html");
    } 
//.................
 
 public function user1List(){
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $user1model=new user1model();
        $result=$user1model->user1List();
        $this->smarty->assign("arr",$result);
        $this->smarty->display("userlist.html");
    }
        public function deleteUser1(){
        $id=$_GET['delete2'];
        include DOCMENT_ROOT.'/admin/model/indexmodel.class.php';
        $user1model=new user1model();
        $result=$user1model->deleteUser1($id);
        echo $result;
    }
}

